import React from 'react'
import { FormItem } from '../../../components/VForm/interface'
import VForm from '../../../components/VForm'
import { Button, Form, Select, message } from 'antd'
import { SumbitDriverInfo } from './service'

export default function DriverInfo() {
  const [form] = Form.useForm()
  const filterOption = (input: string, option?: { label: string; value: string }) =>
  (option?.label ?? '').includes(input);
  const formItems: FormItem[] = [
    {
      name: 'diver_name',
      label: '驾驶员姓名',
      required: true,
      type: 'input'
    },
    {
      name: 'status',
      label: '驾驶员状态',
      required: true,
      type: 'custom',
      // 空闲、出车、请假
      customNode:  <Select showSearch filterOption={filterOption} options={[{ value: '空闲', label: '空闲' }, { value: '出车', label: '出车' }, { value: '请假', label: '请假' }]}
    />
    },
    {
      name: 'phone',
      label: '手机号',
      required: false,
      type: 'input',
      rule:{pattern:new RegExp('^[1][3,4,5,7,8][0-9]{9}$'),message:'请输入正确的手机号'}
    },
    {
      name: 'id',
      label: '身份证',
      required: true,
      type: 'input',
      rule:{pattern:new RegExp('^[0-9]{17}[0-9X]$'),message:'请输入正确的身份证号'}
    },
    {
      name: 'license_id',
      label: '驾驶证',
      required: true,
      type: 'input'
    }
  ]
  const handleSumbit = async () => {
    const values=form.getFieldsValue();
    /** 接口 */
    await SumbitDriverInfo(values).then(res=>{
      if(res.data.result==="SUCCESS"){
        message.success('提交成功');
      }
    })
  }
  return (
    <div className="Vform-container">
      <div className="Vform">
        <VForm formItems={formItems} form={form} />
      </div>

      <div className="sumbit-btn">
        <Button type="primary" onClick={handleSumbit}>
          提交
        </Button>
      </div>
    </div>
  )
}
